// *** LICENSE HEADER ***
// Filename: ./colorviewer.cpp
// This file is part of Nodewarz 0.1
// Nodewarz is a 3d OpenGL strategy game
// Copyright (C) 2007 CZestmyr
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
// *** END LICENSE HEADER ***
#include "colorviewer.h"

colorviewer::colorviewer(int newX, int newY, int newW, int newH, int id):
    guielement(newX, newY, "", id) {
    w = newW;
    h = newH;
    x = newX;
    y = newY;
    r = g = b = 0;
}

colorviewer::~colorviewer(){}

int colorviewer::Click(int clickX, int clickY){
    if (clickX  >= x && clickX < x + 160 && clickY >= y && clickY < y + 20)
        return id;
    else return 0;
}

int colorviewer::Release(int clickX, int clickY){
    return Click(clickX, clickY);
}

void colorviewer::SetColors(GLubyte red, GLubyte green, GLubyte blue){
    r = red; g = green; b = blue;
}

void colorviewer::GetColors(GLubyte& red, GLubyte& green, GLubyte& blue){
    red = r; green = g; blue = b;
}

void colorviewer::Draw(fonts* fontDrawer){
    glDisable(GL_BLEND);
    glDisable(GL_DEPTH_TEST);
    glDisable(GL_TEXTURE_2D);

    glBegin(GL_TRIANGLES);
    glColor3ub(r, g, b);
    glVertex2i(x, _HEIGHT-y);
    glVertex2i(x, _HEIGHT-y-h);
    glVertex2i(x+w, _HEIGHT-y-h);
    glVertex2i(x+w, _HEIGHT-y-h);
    glVertex2i(x+w, _HEIGHT-y);
    glVertex2i(x, _HEIGHT-y);
    glEnd();

    glColor3ub(255,255,255);
    glBegin(GL_LINES);
    glVertex2i(x, _HEIGHT-y);
    glVertex2i(x, _HEIGHT-y-h);
    glVertex2i(x, _HEIGHT-y-h);
    glVertex2i(x+w, _HEIGHT-y-h);
    glVertex2i(x+w, _HEIGHT-y-h);
    glVertex2i(x+w, _HEIGHT-y);
    glVertex2i(x+w, _HEIGHT-y);
    glVertex2i(x, _HEIGHT-y);
    glEnd();
}
